<template>
  <footer class="footer">
    <span class="todo-count">剩余<strong>{{ leftTodo }}</strong></span>
    <ul class="filters">
      <!-- 动态class判断type是什么，添加点击事件 -->
      <li>
        <a @click="clickTypeFn('all')" :class="{selected: type === 'all'}" href="javascript:;" >全部</a>
      </li>
      <li>
        <a @click="clickTypeFn('no')" :class="{selected: type === 'no'}" href="javascript:;">未完成</a>
      </li>
      <li>
        <a @click="clickTypeFn('yes')" :class="{selected: type === 'yes'}" href="javascript:;" >已完成</a>
      </li>
    </ul>
    <!-- 如果leftTodo等于0就隐藏，绑定清除完成 -->
    <button class="clear-completed" v-show="leftTodo != 0" @click="$emit('clearDone')">清除已完成</button>
  </footer>
</template>

<script>
export default {
  props:{
    list:{
      type: Array,
      required: true
    },
    type:{
      type: String,
      required: true
    }
  },
  computed:{
    // 计算剩余
    leftTodo(){
      return this.list.filter(item => !item.isDone).length
    }
  },
  methods:{
    clickTypeFn(val){
      // 监听clickType
      this.$emit('clickType', val)
    }
  }
}
</script>